package com.hongxun.modules.csg.controller;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;

import com.hongxun.common.utils.*;
import com.hongxun.common.validator.ValidatorUtils;
import com.hongxun.common.validator.group.UpdateGroup;
import com.hongxun.modules.bss.entity.DPictureEntity;
import com.hongxun.modules.bss.service.DPictureService;
import com.hongxun.modules.csg.entity.*;
import com.hongxun.modules.csg.service.CPBaseService;
import com.hongxun.modules.csg.service.CScheduleReportService;
import com.lowagie.text.*;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.rtf.RtfWriter2;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import com.hongxun.modules.csg.service.CScheduleService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 项目进度
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-09-11 09:33:49
 */
@RestController
@RequestMapping("/csg/cschedule")
public class CScheduleController {
	@Autowired
	private CScheduleService cScheduleService;
	@Autowired
	private CPBaseService cPBaseService;
	@Autowired
	private CScheduleReportService cScheduleReportService;
	@Autowired
	private DPictureService dPictureService;
	@Value("${com.hongxun.IMAGEROTT}")
	private String ROOT;

	
	/**
	 * 列表
	 */

	@RequestMapping("/list")
	@RequiresPermissions("csg:cschedule:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
        String wheres =" 1=1 ";

        if(params.get("pGuid") != null && !params.get("pGuid").toString().equals("")){
        	wheres += " and p_guid='"+params.get("pGuid").toString()+"'";
		}else{
			wheres += " and 1=2 ";
		}
//		if(params.get("pName") != null && !params.get("pName").toString().equals("")){
//			wheres += " and p_name like'%"+params.get("pName").toString()+"%'";
//		}
//		if(params.get("sName") != null && !params.get("sName").toString().equals("")){
//			if(Integer.parseInt(params.get("sName").toString())==0){
//
//			}else{
//				wheres += " and s_sort='"+params.get("sName").toString()+"'";
//			}
//		}
//
//		if(params.get("inverTime") != null && !params.get("inverTime").toString().equals("")){
//			wheres += " and inverTime like'%"+params.get("inverTime").toString()+"%'";
//		}

		if(query.get("state")!=null&&query.get("state").toString().equals("isdelno")) {
			wheres += " and  s_datastate != '删除' ";
		}

        query.put("filterSql",wheres+" ");
//		List<CScheduleEntity> cScheduleList = cScheduleService.queryList(query);
		List<CScheduleEntity> cScheduleList = cScheduleService.queryListForInverTime(query);
		int total = cScheduleService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(cScheduleList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}




	/**
	 *
	 * @param params
	 * @return
	 */
	@RequestMapping("/select")

	public R select(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		String wheres =" 1=1 ";
		if(query.get("pGuid")!=null&&!query.get("pGuid").toString().equals(""))
		{
			wheres+=" and  p_guid = '" + query.get("pGuid").toString()+"' ";
		}
		if(query.get("sGuid")!=null&&!query.get("sGuid").toString().equals(""))
		{
			wheres+=" and  p_guid = '" + query.get("pGuid").toString()+"' ";
		}

		wheres+=" and  s_datastate != '删除' ";
		query.put("filterSql",wheres+" ");
		List<CScheduleEntity> cScheduleEntities = cScheduleService.queryList(query);
		return R.ok().put("returnlist", cScheduleEntities);
	}




	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{guid}")
	@RequiresPermissions("csg:cschedule:info")
	public R info(@PathVariable("guid") String guid){
		CScheduleEntity cSchedule = cScheduleService.queryObject(guid);
		
		return R.ok().put("cSchedule", cSchedule);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("csg:cschedule:save")
	public R save(@RequestBody CScheduleEntity cSchedule){
		cSchedule.setSDatastate("新增");
		cScheduleService.save(cSchedule);
		
		return R.ok();
	}




	@RequestMapping("/saveNew/{pGuid}")
	@RequiresPermissions("csg:cschedule:save")
	public R save(@RequestBody CScheduleEntity cSchedule ,
				  @PathVariable("pGuid") String pGuid)
	{

		CPBaseEntity cpBaseEntity = cPBaseService.queryObject(pGuid);
		cSchedule.setPName(cpBaseEntity.getPBName());
		cSchedule.setPGuid(pGuid);
		cSchedule.setSDatastate("新增");
		cScheduleService.save(cSchedule);

		return R.ok();
	}


	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("csg:cschedule:update")
	public R update(@RequestBody CScheduleEntity cSchedule){
		ValidatorUtils.validateEntity(cSchedule, UpdateGroup.class);
		cSchedule.setSDatastate("修改");
		cScheduleService.update(cSchedule);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("csg:cschedule:delete")
	public R delete(@RequestBody String[] guids){
		cScheduleService.deleteBatch(guids);
		
		return R.ok();
	}


	/**
	 *  进度导出
	 *
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws DocumentException
	 */
	@RequestMapping("/exports")
	public void exports(HttpServletRequest request , HttpServletResponse response) throws IOException, DocumentException {

		Map<String , Object> cScheduleMap = new HashMap<>();

		//进度
		String pGuid = request.getParameter("pGuid");
		String cScheduleWhere = " 1=1 and p_guid='"+pGuid+"'";
		cScheduleMap.put("filterSql",cScheduleWhere);
		List<CScheduleEntity> cScheduleEntityList = cScheduleService.queryList(cScheduleMap);

		CPBaseEntity cpBaseEntity = cPBaseService.queryObject(pGuid);

//		CScheduleEntity cScheduleEntity = cScheduleService.queryObject(guid);
		//设置下载文件的格式(表格)msword
//		response.setContentType("application/vnd.ms-excel;charset=utf-8");//表格
		response.setContentType("application/msword;charset=utf-8");//文档
		try {
//			response.setHeader("Content-Disposition", "attachment;filename=" + new String(((cScheduleEntity.getSName()==null?"堆放点材料":cScheduleEntity.getSName()) + ".xlsx").getBytes(), "iso-8859-1"));
			response.setHeader("Content-Disposition", "attachment;filename=" + new String(((cpBaseEntity.getPBName()==null?"施工项目进度":cpBaseEntity.getPBName()) + "-项目进度.doc").getBytes(), "iso-8859-1"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		//A4纸横向打印
		Document document = new Document(PageSize.A4.rotate());
		//字体设置
		BaseFont bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

		RtfWriter2.getInstance(document, response.getOutputStream());
		Font titleFontye = new Font(bfChinese,8,Font.BOLD);
		HeaderFooter footer = new HeaderFooter(new Phrase("页码：",titleFontye), true);
		footer.setAlignment(1);
		footer.setBorder(Rectangle.NO_BORDER);
		document.setFooter(footer);
		document.open();
		//文件内容及格式
		setexports(document,bfChinese,cScheduleEntityList, pGuid , cpBaseEntity);

		document.close();
	}


	/**
	 * 文件内容及格式
	 *
	 * @param document
	 * @param bfChinese
	 * @param
	 * @throws DocumentException
	 */
	public void setexports(Document document  ,BaseFont bfChinese ,	List<CScheduleEntity> cScheduleEntityList ,String pGuid ,CPBaseEntity cpBaseEntity ) throws DocumentException {

		Map<String ,Object> cStackMap = new HashMap<>();
		// TODO: 2018/9/25  查询项目进度

		//进度名称
//		String sPName = cScheduleEntity.getSName();

		//所属项目进度下进度填报信息
		String cStackWhere = " 1=1 and p_guid='"+pGuid+"' and s_r_datastate != '删除'";
		cStackMap.put("filterSql",cStackWhere);
		List<CScheduleReportEntity> cScheduleReportEntityList = cScheduleReportService.queryListToExport(cStackMap);


		//3.获取项目名称
//		String pGuid = cScheduleEntity.getPGuid();
//		CPBaseEntity cpBaseEntity = cPBaseService.queryObject(pGuid);


		//表题字体
		Font titleFont = new Font(bfChinese,11,Font.BOLD);
		//表格字体
		Font contextFont = new Font(bfChinese, 8, Font.NORMAL);
		//签字字体
		Font qinFont = new Font(bfChinese, 10, Font.NORMAL);
//		Paragraph title = new Paragraph("配网技改/修理项目申请书（适用于总投资100万元以下的配网技改/修理项目）");
//		title.setAlignment(Element.ALIGN_CENTER);
//		title.setFont(titleFont);
//		document.add(title);

		Table table = new Table(6);
		int[] withs = {1,1,1,1,1,1};
		table.setWidths(withs);
		/** 表格所占页面宽度 author:yyli Sep 15, 2010*/
		table.setWidth(90);
		/** 居中显示 author:yyli Sep 15, 2010*/
		table.setAlignment(Element.ALIGN_CENTER);
		/** 自动填满 author:yyli Sep 15, 2010*/
		table.setAutoFillEmptyCells(true);

		OutPutUtils.addcell(table, cpBaseEntity.getPBName()+"-项目进度", 0, 6, true, contextFont);

		//材料清单列表
		OutPutUtils.addcell(table, "进度名称", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "记录主题", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "记录时间", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "记录详情", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "填报人", 0, 0, true, contextFont);
		OutPutUtils.addcell(table, "更新时间", 0, 0, true, contextFont);

//		for (CScheduleEntity cScheduleEntity : cScheduleEntityList) {

		for(CScheduleReportEntity cScheduleReportEntity :cScheduleReportEntityList)
		{

			OutPutUtils.addcell(table, cScheduleReportEntity.getSName(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table, cScheduleReportEntity.getSRTheme(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table, cScheduleReportEntity.getSRAddtime()==null?"": DateUtils.format(cScheduleReportEntity.getSRAddtime(),"yyyy-MM-dd HH:mm:ss"), 0, 0, true, contextFont);
			OutPutUtils.addcell(table, cScheduleReportEntity.getSRDetails(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table, cScheduleReportEntity.getSRUsername(), 0, 0, true, contextFont);
			OutPutUtils.addcell(table, cScheduleReportEntity.getSRUpdatetime()==null?"":DateUtils.format(cScheduleReportEntity.getSRUpdatetime(),"yyyy-MM-dd HH:mm:ss"), 0, 0, true, contextFont);
		}
		document.add(table);
	}


	/**
	 * 导出进度照片
	 *
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws DocumentException
	 */
	@RequestMapping("/exportsimg")
	public void exportsimg(HttpServletRequest request, HttpServletResponse response) throws IOException, DocumentException {

		Map<String , Object> cScheduleMap = new HashMap<>();
		String pGuid = request.getParameter("pGuid");

		String cScheduleWhere = " 1=1 and p_guid='"+pGuid+"'";
		cScheduleMap.put("filterSql",cScheduleWhere);
		List<CScheduleEntity> cScheduleEntityList = cScheduleService.queryList(cScheduleMap);

		CPBaseEntity cpBaseEntity = cPBaseService.queryObject(pGuid);

//		CScheduleEntity cScheduleEntity = cScheduleService.queryObject(guid);

		response.setContentType("application/msword;charset=utf-8");
		try {
			response.setHeader("Content-Disposition", "attachment;filename=" + new String(((cpBaseEntity.getPBName()==null?"":cpBaseEntity.getPBName()+"-项目进度照片.doc")).getBytes(), "iso-8859-1"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

		Document document = new Document();
		BaseFont bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

		RtfWriter2.getInstance(document, response.getOutputStream());
		Font titleFontye = new Font(bfChinese,8,Font.BOLD);
		HeaderFooter footer = new HeaderFooter(new Phrase("页码：",titleFontye), true);
		footer.setAlignment(1);
		footer.setBorder(Rectangle.NO_BORDER);
		document.setFooter(footer);
		document.open();
		setexportsimg(document,bfChinese,cScheduleEntityList , pGuid , cpBaseEntity);

		document.close();
	}

	/**
	 * 设置表格格式
	 *
	 * @param document
	 * @param bfChinese
	 * @param
	 * @throws DocumentException
	 * @throws IOException
	 */
	public void setexportsimg(Document document  ,BaseFont bfChinese ,	List<CScheduleEntity> cScheduleEntityList , String pGuid , CPBaseEntity cpBaseEntity ) throws DocumentException, IOException {


		//表题字体
		Font titleFont = new Font(bfChinese,11,Font.BOLD);
		//表格字体
		Font contextFont = new Font(bfChinese, 8, Font.NORMAL);
		// 签字字体
		Font qinFont = new Font(bfChinese, 10, Font.NORMAL);
		Paragraph title = new Paragraph((cpBaseEntity.getPBName()==null?"":cpBaseEntity.getPBName()) + "-进度照片");
		title.setAlignment(Element.ALIGN_CENTER);
		title.setFont(titleFont);
		document.add(title);

		addCScheduleImg(document, contextFont,cScheduleEntityList, pGuid , cpBaseEntity);

	}

	/**
	 *	进度照片内容组装
	 *
	 * @param document
	 * @param
	 * @param contextFont
	 * @param
	 * @throws DocumentException
	 * @throws IOException
	 *
	 * 进度的照片，应按进度类型分组且按时间顺序先后排列；
	 * 进度排序：施工复测、安全技术交流、现场开工、。。。
	 *
	 */
	private void addCScheduleImg(Document document, Font contextFont,
								 List<CScheduleEntity> cScheduleEntityList,
								 String pGuid , CPBaseEntity cpBaseEntity) throws DocumentException, IOException {

		//一个进度下包含多条进度记录
		for (CScheduleEntity cScheduleEntity : cScheduleEntityList) {
			Map<String, Object> cScheduleMapss = new HashMap<>();
			String cScheduleWheres = " 1=1 and p_guid='" + pGuid + "' and s_guid='" + cScheduleEntity.getGuid() + "'and s_r_datastate !='删除' ";
			cScheduleMapss.put("filterSql", cScheduleWheres + " ");
			List<CScheduleReportEntity> cScheduleReportEntityList = cScheduleReportService.queryList(cScheduleMapss);

		for (CScheduleReportEntity cScheduleReportEntity : cScheduleReportEntityList) {
			Map<String, Object> cScheduleMap = new HashMap<>();
			String cScheduleWhere = " 1=1 and p_guid= '" + pGuid +
					"' and p_status = '施工' and p_label like'%进度%'" +
					" and p_p_guid='" + cScheduleReportEntity.getGuid() + "' and p_datastate !='删除' ORDER BY p_label ASC,p_time DESC";
			cScheduleMap.put("filterSql", cScheduleWhere + " ");
			List<DPictureEntity> dPictureList = dPictureService.queryListForPlabel(cScheduleMap);
			if (dPictureList.size() > 0) {

				Table table = new Table(6);
				int[] withs = {1, 2, 1, 2, 1, 2};
				table.setWidths(withs);
				/** 表格所占页面宽度 author:yyli Sep 15, 2010 */
				table.setWidth(90);
				/** 居中显示 author:yyli Sep 15, 2010 */
				table.setAlignment(Element.ALIGN_CENTER);
				/** 自动填满 author:yyli Sep 15, 2010 */
				table.setAutoFillEmptyCells(true);

				OutPutUtils.addcell(table, cpBaseEntity.getPBName() + "("+cScheduleReportEntity.getSRTheme()+")", 0, 6, true, contextFont);
				int chishu = dPictureList.size() / 3;
				int yushu = dPictureList.size() % 3;

				if (yushu > 0) {
					chishu = chishu + 1;
				}
				//一行显示3张照片
				for (int i = 0; i < chishu; i++) {
					boolean one = false;
					boolean two = false;
					boolean three = false;

					if ((3 * i) < dPictureList.size()) {
						one = true;
					}
					if (((3 * i) + 1) < dPictureList.size()) {
						two = true;
					}
					if (((3 * i) + 2) < dPictureList.size()) {
						three = true;
					}
					if (one) {
						File file = new File(ROOT + dPictureList.get(3 * i).getPServeraddress());
						if (file.exists()) {
							OutPutUtils.addcellimg(table, ROOT + dPictureList.get(3 * i).getPServeraddress(), 8, 2, true, contextFont);
						} else {
							OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);
						}
					} else {
						OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
					}
					if (two) {
						File file = new File(ROOT + dPictureList.get((3 * i) + 1).getPServeraddress());
						if (file.exists()) {
							OutPutUtils.addcellimg(table, ROOT + dPictureList.get((3 * i) + 1).getPServeraddress(), 8, 2, true, contextFont);
						} else {
							OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);
						}
					} else {
						OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
					}
					if (three) {
						File file = new File(ROOT + dPictureList.get((3 * i) + 2).getPServeraddress());
						if (file.exists()) {
							OutPutUtils.addcellimg(table, ROOT + dPictureList.get((3 * i) + 2).getPServeraddress(), 8, 2, true, contextFont);
						} else {
							OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);
						}
					} else {
						OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
					}

					//照片名称
					OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
					if (one) {
						if (dPictureList.get(3 * i).getPLabel().equals("进度,xc")) {
							OutPutUtils.addcell(table, "现场照片", 0, 0, true, contextFont);
						} else {
							OutPutUtils.addcell(table, "资料照片", 0, 0, true, contextFont);
						}
//						OutPutUtils.addcell(table, dPictureList.get(3 * i).getPLabel(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
					if (two) {
						if (dPictureList.get((3 * i) + 1).getPLabel().equals("进度,xc")) {
							OutPutUtils.addcell(table, "现场照片", 0, 0, true, contextFont);
						} else {
							OutPutUtils.addcell(table, "资料照片", 0, 0, true, contextFont);
						}
//						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPLabel(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
					if (three) {
						if (dPictureList.get((3 * i) + 2).getPLabel().equals("进度,xc")) {
							OutPutUtils.addcell(table, "现场照片", 0, 0, true, contextFont);
						} else {
							OutPutUtils.addcell(table, "资料照片", 0, 0, true, contextFont);
						}
//						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPLabel(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}

					//所属进度
					OutPutUtils.addcell(table, "所属进度", 0, 0, true, contextFont);
					if (one) {
						if (dPictureList.get(3 * i).getPPGuid().equals(cScheduleReportEntity.getGuid())) {
							OutPutUtils.addcell(table, cScheduleReportEntity.getSName(), 0, 0, true, contextFont);
						}
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "所属进度", 0, 0, true, contextFont);
					if (two) {
						if (dPictureList.get((3 * i) + 1).getPPGuid().equals(cScheduleReportEntity.getGuid())) {
							OutPutUtils.addcell(table, cScheduleReportEntity.getSName(), 0, 0, true, contextFont);
						}
//						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPLabel(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "所属进度", 0, 0, true, contextFont);
					if (three) {
						if (dPictureList.get((3 * i) + 2).getPPGuid().equals(cScheduleReportEntity.getGuid())) {
							OutPutUtils.addcell(table, cScheduleReportEntity.getSName(), 0, 0, true, contextFont);
						}
//						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPLabel(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}

					//照片来源：相册or相机
					OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
					if (one) {
						OutPutUtils.addcell(table, dPictureList.get(3 * i).getPPResour(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
					if (two) {
						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPPResour(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
					if (three) {
						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPPResour(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}

					//时间
					OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
					if (one) {
						OutPutUtils.addcell(table, dPictureList.get(3 * i).getPTime() == null ? "" : DateUtils.format(dPictureList.get(3 * i).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
					if (two) {
						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPTime() == null ? "" : DateUtils.format(dPictureList.get((3 * i) + 1).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
					if (three) {
						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPTime() == null ? "" : DateUtils.format(dPictureList.get((3 * i) + 2).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
				}
				document.add(table);
			}
			}
		}
	}



	public static boolean compare(String time1,String time2) throws ParseException {
		//如果想比较日期则写成"yyyy-MM-dd"就可以了  
 		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		//将字符串形式的时间转化为Date类型的时间  
 		Date a = sdf.parse(time1);
 		Date b = sdf.parse(time2);
 		//Date类的一个方法，如果a早于b返回true，否则返回false  
 		if(a.before(b))
 			return true;
 		else
 			return false;

 }





}
